package com.hht.study.batch.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author hht
 * @date 2022/3/3
 */
@Configuration
public class ThreadPoolConfig {

    /**
     * 获取当前处理器核数
     */
    private static final int CORE_NUM=Runtime.getRuntime().availableProcessors();

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(CORE_NUM);
        executor.setMaxPoolSize(CORE_NUM*2);
        executor.setKeepAliveSeconds(60);

        return executor;
    }
}
